﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using CMS.BaseEntity;

namespace ElectronicSelling.DataAccess
{
    public class OrderAccess
    {
        public static bool IsInsertOrder(Order order)
        {
            return DataAccess.ExeStoredWithParamToBool("usp_OrderInsert", "@CustomerId", order.CustomerId, "@CreateDate", order.CreateDate, "@Total", order.Total, "@Note", order.Note);
        }

        public static int GetMaxOrderId()
        {
            return DataAccess.ExeSQLGetInt("usp_OrderSelectMaxId");
        }

        public static bool IsInsertOrderDetail(OrderDetail orderDetail)
        {
            return DataAccess.ExeStoredWithParamToBool("usp_OrderDetailInsert", "@OrderId", orderDetail.OrderId, "@ProductId", orderDetail.ProductId, "@Quantity", orderDetail.Quantity);
        }

        public static DataTable GetOrderInDay(Order order)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable("usp_OrderSelectByCusInDay", "@CustomerId", order.CustomerId);
            return dt;
        }

        public static DataTable GetOrderListByCusId(Order order)
        {
            DataTable dt = DataAccess.ExeStoredWithParamToDataTable("[usp_OrderSelectAllByCus]", "@CustomerId", order.CustomerId);
            return dt;
        }

        public static bool IsUpdatedPassWord(User user)
        {
            return DataAccess.ExeStoredWithParamToBool("usp_UserPassWordChange", "@UserId", user.UserId, "@NewPass", user.Password);
        }

        public static bool IsDeletedOrderByCus(Order order)
        {
            return DataAccess.ExeStoredWithParamToBool("usp_OrderDeleteByCustomer", "@OrderId", order.OrderId);
        }

        /// <summary>
        /// get status order: processed or not
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static DataTable GetOrderStatus(Order order)
        {
            return DataAccess.ExeStoredWithParamToDataTable("usp_CheckOrderIsProcessed", "@OrderId", order.OrderId);
        }

        public static DataTable GetOrderDetail(OrderDetail orderDetail)
        {
            return DataAccess.ExeStoredWithParamToDataTable("usp_DetailOrderSelectByOrderId", "@OrderId", orderDetail.OrderId);
        }
    }
}